import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * This class is Return check assignment UI
 */
public class SemUI extends JPanel {
	/**
	 * title for the current window  
	 */
	private JLabel lbltitle = null;
	/**
	 * label id
	 */
	private JLabel lblID = null;
	/**
	 * label name
	 */
	private JLabel lblName = null;
	/**
	 * label for start date
	 */
	private JLabel lblStratDate = null;
	private JLabel lblFinishDate  = null;
	/**
	 *  TextField  for id
	 */
	private JTextField TextID = null;
	/**
	 *  TextField  for Name
	 */
	private JTextField TextName = null;
	/**
	 *  TextField  for  number of hours
	 */
	private JTextField TextNumOfHours = null;
	/**
	 *  TextField  for  teacher unit 
	 */
	private JTextField TextTUnit = null;
	/**
	 * create semester button
	 */
	private JButton btnCreateSem = null;
	/**
	/back button
	 * 
	 */
	public JButton btnBack = null;
	/**
	 * help button
	 */
	public JButton btnHelp = null;
	
	private JPanel curPanel;
	
	private String id;
	private String name;
	private String start;
	private String finish;

	
	
	public SemUI () {
		super();
		initialize();
	}
	
	private void initialize() {
		curPanel = this;
		btnCreateSem = new JButton();
		btnCreateSem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Sem sem = new Sem(id,name,start,finish);
				SQL s = new SQL(sem,15);
				s.accept();
				if (s.getMsg().equals("semCreate"))
				{
					AddClassToCourseUI addClassToCourseUI = new AddClassToCourseUI();
					System.out.println("create sem");
					Global.main.setContentPane(addClassToCourseUI);
					addClassToCourseUI.btnBack.addActionListener(new ActionListener() {   //back from open addClassToCourseUI
						public void actionPerformed(ActionEvent arg0) {
							Global.main.setContentPane(curPanel);
							curPanel.setVisible(true);
						}
					});
				}
				
			}
		});
		btnCreateSem.setBounds(new Rectangle(130, 230, 200, 25));
		btnCreateSem.setText("Create Semster");
		this.add(btnCreateSem,null);
		this.setVisible(true);
		
		
		lblID = new JLabel("Semester ID:");
		lblID.setBounds(83, 60, 110, 14);
		this.add(lblID);	
			
		TextID = new JTextField();
		TextID.setBounds(new Rectangle(194, 60, 128, 25));
		TextID.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				id=TextID.getText();			
			}
		}
		);
		this.add(TextID,null);
		
		
		lblName = new JLabel("Semester Name:");
		lblName.setBounds(83, 100, 110, 14);
		this.add(lblName);	
		
		TextName = new JTextField();
		TextName.setBounds(new Rectangle(194, 100, 128, 25));
		TextName.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				name = TextName.getText();
			}
		}
		);
		this.add(TextName,null);
		
		
		lblStratDate = new JLabel("Strat Date:");
		lblStratDate.setBounds(83, 140, 110, 14);
		this.add(lblStratDate);
		
		TextNumOfHours = new JTextField();
		TextNumOfHours.setBounds(new Rectangle(194, 140, 128, 25));
		TextNumOfHours.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				start = TextNumOfHours.getText();	
				//num.getInteger(n);		
			}
		}
		);
		this.add(TextNumOfHours,null);
		
		
		lblFinishDate = new JLabel("Finish Date:");
		lblFinishDate.setBounds(83, 180, 110, 14);
		this.add(lblFinishDate);	
		
		TextTUnit = new JTextField();
		TextTUnit.setBounds(new Rectangle(194, 180, 128, 25));
		TextTUnit.addFocusListener(new java.awt.event.FocusAdapter() 
		{
			public void focusLost(java.awt.event.FocusEvent e) 
			{
				System.out.println("focusLost()"); 
				finish=TextTUnit.getText();			
			}
		}
		);
		this.add(TextTUnit,null);
		

		lbltitle = new JLabel("Open New Semester");
		lbltitle.setBounds(146, 26, 151, 14);

		this.setSize(400, 321);
		this.setLayout(null);
		
		this.add(lbltitle);
	
		btnBack = new JButton("Back");
		btnBack.setBounds(187, 283, 86, 25);
		this.add(btnBack,null);
		this.setVisible(true);
		
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Enter the new Semester details and then"," click on 'Create Semester' button");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);
		this.setVisible(true);
		
	}
}
